package com.jy.event.domain;

import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.util.Date;

/**
 * 入库记录
 * Created by hanxi on 2017/8/1.
 */
@Entity
@Data
@NoArgsConstructor
public class StockInTransaction {
    @Id
    @Column(length = 50)
    private String id;
    private String productId;
    private String productName;
    private int quantity;
    private double amount = 0;
    private String storeId;

    @Enumerated(EnumType.STRING)
    private StockInType type;
    /**
     * 关联Id, 正常入库就关联入库ID，盘点入库就关联盘点id
     */
    private String refId;
    /**
     * 操作人
     */
    private String operator;
    /**
     * 操作时间
     */
    @Column(columnDefinition = "TIMESTAMP(3) NULL")
    private Date operTime;
    @Column(insertable = false, updatable = false, columnDefinition = "TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP(3)")
    private Date addTime;

    /**
     * 是否按件入库
     */
    @Column(columnDefinition = "VARCHAR(10) default 'SINGLE'")
    @Enumerated(EnumType.STRING)
    private StockUnit unit = StockUnit.SINGLE;

    public StockInTransaction(String id, String productId, String productName, int quantity,
                              StockInType type, String refId, String operator, String storeId,
                              double amount) {
        this.id = id;
        this.productId = productId;
        this.productName = productName;
        this.quantity = quantity;
        this.type = type;
        this.refId = refId;
        this.operator = operator;
        this.operTime = new Date();
        this.storeId = storeId;
        this.amount = amount;
    }
}
